<?php 
namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use cmf\controller\BaseController;
use think\Db;
class RedisController extends BaseController{



	private static $handler;

	private  function handler(){
		if(!self::$handler){

			self::$handler = new \Redis();
			self::$handler -> connect('127.0.0.1','6379');
		}
		return self::$handler;
	}

	public function gets($key){
		$value =$this->handler() -> get($key);
		$value_serl = @unserialize($value);
		if(is_object($value_serl)||is_array($value_serl)){
			return $value_serl;
		}
		return $value;
	}

	public   function set($key,$value,$timeout){
		if(is_object($value)||is_array($value)){
			$value = serialize($value);
		}
		$handler=$this->handler();
	    return $handler -> set($key,$value,$timeout);
	}
	public   function setnx($key,$value){
		if(is_object($value)||is_array($value)){
			$value = serialize($value);
		}
		$handler=$this->handler();
		return $handler -> setnx($key,$value);
	}
	public   function lpush($key,$value){
		if(is_object($value)||is_array($value)){
			$value = serialize($value);
		}
		$handler=$this->handler();
		return $handler -> lpush($key,$value);
	}
	public   function rpush($key,$value){
		if(is_object($value)||is_array($value)){
			$value = serialize($value);
		}
		$handler=$this->handler();
		return $handler -> rpush($key,$value);
	}
    public   function lpop($key){
    	$value =$this->handler() -> lpop($key);
    	$value_serl = @unserialize($value);
    	if(is_object($value_serl)||is_array($value_serl)){
    		return $value_serl;
    	}
    	return $value;
	}

    function delete(){
   echo 2222;
    }


























}